<?php
require_once("dao/brackets_dao.php");
require_once("dao/tournaments_dao.php");

class reportloss_controller extends abstract_controller {
	
	function prepare_model($request_params, Smarty $smarty_obj) {
		
		$name = isset($_GET['name']) ? htmlentities($_GET['name']) : "";
		$pointsfor = isset($_GET['pointsfor']) ? htmlentities($_GET['pointsfor']) : "";
		$pointsagainst = isset($_GET['pointsagainst']) ? htmlentities($_GET['pointsagainst']) : "";	
			
		$user = isset($_SESSION['user']) ? htmlentities($_SESSION['user']) : "";

		$smarty_obj->assign("page_title", "Tour Builder");
		$smarty_obj->assign("name", $name);
		
		if(!(empty($pointsfor) && empty($pointsagainst))) {
			$smarty_obj->assign("confirmed", true);
			$runde = brackets_dao::findRound($user, $name);
			tournaments_dao::addLossPlayer($user,$name);
			brackets_dao::reportLoss($user,$name, $pointsfor, $pointsagainst, $runde);
		}
		else {
			$smarty_obj->assign("confirmed", false);
		}
		
	}
	
}
?>